package com.apexwear.apexutils.data;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.apex.bluetooth.callback.EABleCallback;
import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.callback.PersonInfoCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.EABleConnectState;
import com.apex.bluetooth.enumeration.QueryWatchInfoType;
import com.apex.bluetooth.model.EABlePersonInfo;

public class PersonData extends ViewModel {


    public MutableLiveData<EABlePersonInfo> getPersonInfo() {
        MutableLiveData<EABlePersonInfo> mutableLiveData = new MutableLiveData<>();
        if (EABleManager.getInstance().getDeviceConnectState() != EABleConnectState.STATE_CONNECTED) {
            mutableLiveData.postValue(null);
        } else {
            EABleManager.getInstance().queryWatchInfo(QueryWatchInfoType.user_info, new PersonInfoCallback() {
                @Override
                public void personInfo(EABlePersonInfo eaBlePersonInfo) {
                    mutableLiveData.postValue(eaBlePersonInfo);
                }

                @Override
                public void mutualFail(int i) {
                    mutableLiveData.postValue(null);
                }
            });
        }
        return mutableLiveData;
    }

    public MutableLiveData<Boolean> setPersonInfo(EABlePersonInfo eaBlePersonInfo) {
        MutableLiveData<Boolean> mutableLiveData = new MutableLiveData<>();
        if (EABleManager.getInstance().getDeviceConnectState() != EABleConnectState.STATE_CONNECTED) {
            mutableLiveData.postValue(false);
        } else {
            EABleManager.getInstance().setUserInfo(eaBlePersonInfo, new GeneralCallback() {
                @Override
                public void result(boolean b,int i) {
                    mutableLiveData.postValue(b);
                }

                @Override
                public void mutualFail(int i) {
                    mutableLiveData.postValue(false);
                }
            });
        }
        return mutableLiveData;
    }
}
